public class Tickets implements Runnable{
    private int tickets = 5;
    Object lock = new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (lock) {
                if (tickets >0) {
                    System.out.println(Thread.currentThread().getName() + "出票:" + tickets-- + "张");
                }else {
                    break;
                }
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
